# -*- coding: utf-8 -*-

from collections import deque


class Solution:

    def __init__(self):
        self.__pairs = deque()

    def is_stable(self, pair):
        for p in self.__pairs:
            m1 = p[0]
            w1 = p[1]
            m2 = pair[0]
            w2 = pair[1]
            if ((m1.prefers(w2) and w2.prefers(m1))
                or (m2.prefers(w1) and w1.prefers(m2))):
                return False
        return True

    def push(self, pair):
        self.__pairs.append(pair)

    def pop(self):
        pair = self.__pairs.pop()
        return pair

    def show(self):
        print self.toString()

    def toString(self):
        str = ''
        for p in self.__pairs:
            str += "(" + p[0].name + ", " + p[1].name + ")\n"
        return str
